package com.lanren.familybookapp.ui.me.model;

import com.lanren.common.app.ApiUrl;
import com.lanren.common.base.impl.BaseModel;
import com.lanren.common.http.HttpManager;
import com.lanren.common.utils.GsonUtils;
import com.lanren.common.utils.LogUtils;
import com.lanren.easyhttp.callback.SimpleCallBack;
import com.lanren.easyhttp.exception.ApiException;
import com.lanren.familybookapp.app.AppUserHelper;
import com.lanren.familybookapp.app.UserInfoBean;
import com.lanren.familybookapp.ui.me.interfaces.IMeModel;

import io.reactivex.disposables.Disposable;

/**
 * @ClassName MeModel
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2019/10/5 17:02
 * @Version 1.0
 */
public class MeModel extends BaseModel {
    public MeModel() {
        initDispoable();
    }

    public void getUserInfo(final IMeModel.MeModel meModel) {
        Disposable disposable = HttpManager.post(ApiUrl.API.USER_INFO_GET)
                .headers(AppUserHelper.getHttpHeaders())
                .execute(new SimpleCallBack<UserInfoBean>() {
                    @Override
                    public void onError(ApiException e) {
                        meModel.onError(e.getCode(), e.getMessage());
                    }

                    @Override
                    public void onSuccess(UserInfoBean userInfoBean) {
                        AppUserHelper.getInstance().setUserInfoBean(userInfoBean);

                        LogUtils.d("USER_INFO_GET=" + GsonUtils.toJson(userInfoBean));
                        meModel.onSuccess();
                    }
                });

        addDisposable(disposable);
    }
}
